<template>
	<view class="body">
		<view class="header">
			<u-tabs  active-color="#F0250E" name="cate_name" :list="list" :is-scroll="false" :current="current"
				@change="change"></u-tabs>
		</view>
		<view class="content" v-for="(item,index) in orderList" :key="index">
			<view class="flex" >
				<u-image  width="68rpx" height="58rpx" :src="asyncImgs.team_bonus.range"></u-image>
				<view class="cont">
					<view class="team">
						{{item.type_name}}
					</view>
					<view class="create_time">
						生成时间：{{ formatDate(item.created_at) }}
					</view>
					<view class="end_time" v-if="item.send_time!=0">
						到账时间：{{ formatDate(item.send_time) }}
					</view>
					<view class="remarks">
						备 注
						<view class="" style="margin-top: 10rpx;">
							{{item.desc}}
						</view>
					</view>
				</view>
				<view class="right">
					<view class="money">
						+{{item.money}}
					</view>
					<view class="alreadyReceived">
						{{item.is_send==0?'未到账':'已到账'}}
					</view>
				</view>
			</view>
		</view>
		<view style="padding:30rpx 0">
			<u-loadmore :status="noMore ? 'nomore': 'loadmore'" />
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [{
					cate_name: '全部'
				}, {
					cate_name: '已到账'
				}, {
					cate_name: '未到账'
				}],
				current: 0,
				noMore: false,
				page: 1,
				orderList: [],
				limit: 10,
				type:0,
			}
		},
		onLoad(option) {
			if(option.current){
				this.current=option.current
			}
			if(option.type){
				// 动态修改标题
				this.type = option.type
				let titleBar = ''
				if (this.type == 14) {
					titleBar = '感恩奖'
				} else {
					titleBar = '佣金明细'
				}
				uni.setNavigationBarTitle({
					title: titleBar
				});
			}
			
			this.getList()
		},
		onReachBottom() {
			console.log('我出发了')
			this.getList(true);
		},
		methods: {
			async getList(isBottom) {
				let newCurrent = null
				if (this.current == 0) {
					newCurrent = -1
				} else if (this.current == 1) {
					newCurrent = 1
				} else {
					newCurrent = 0
				}
			
				// 已经到底
				if (this.noMore) return
				// 触底更新数据
				if (isBottom) {
					this.page++
				}
				const res = await this.$allrequest.teamCenter.temOrder({
					is_send: newCurrent,
					_get_order: 0,
					type:this.type,
					page: this.page,
					limit: this.limit
				});
				if (res.code == 0) {
					this.orderList.push(...res.data.list)
					this.noMore = res.data.totalCount <= this.page * this.limit
				}
			},
			change(index) {
				this.current = index;
				this.page = 1
				this.noMore = false
				this.orderList = []
				this.getList()
			},
			formatDate(timestamp) {
				// 将时间戳转换为毫秒
				let date = new Date(timestamp * 1000);
				// 获取年、月、日、时、分、秒
				let year = date.getFullYear();
				let month = (date.getMonth() + 1).toString().padStart(2, '0'); // 月份从0开始，需要加1
				let day = date.getDate().toString().padStart(2, '0');
				let hours = date.getHours().toString().padStart(2, '0');
				let minutes = date.getMinutes().toString().padStart(2, '0');
				let seconds = date.getSeconds().toString().padStart(2, '0');
			
				// 返回格式化的字符串
				return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
			},
		}
	}
</script>

<style scoped lang="scss">
	.body {
		min-height: 100vh;
		background-color: #F2F2F2;
	}

	.header {
		padding-bottom: 10rpx;
		background-color: #FFF;
		 position: sticky;
		 top: 0;
		 z-index: 1000; /* 确保 z-index 高于其他组件 */
	}

	.content {
		width: 702rpx;
		background: #FFFFFF;
		border-radius: 20rpx;
		margin: 24rpx auto 0rpx;
		.flex {
			display: flex;
			border-bottom: 1px solid #F8F8F8;
			padding: 24rpx;

			.cont {
				margin-left: 24rpx;
				 width: 475rpx;

				.team {
					font-weight: 400;
					font-size: 28rpx;
					color: #262626;
				}

				.create_time {
					font-weight: 400;
					font-size: 24rpx;
					color: #8C8C8C;
					margin-top: 10rpx;
				}

				.end_time {
					font-weight: 400;
					font-size: 24rpx;
					color: #8C8C8C;
					margin-top: 10rpx;
				}

				.remarks {
					font-weight: 400;
					font-size: 24rpx;
					color: #8C8C8C;
					margin-top: 10rpx;
				}

				.commission {
					font-weight: 400;
					font-size: 24rpx;
					color: #8C8C8C;
					margin-top: 10rpx;
				}
			}

			.right {
				.money {
					font-weight: 600;
					font-size: 30rpx;
					color: #262626;
				}

				.alreadyReceived {
					font-weight: 400;
					font-size: 24rpx;
					color: #8C8C8C;
					margin-top: 6rpx;
					float: right;
				}

			}
		}
	}
</style>